import 'dart:convert';

import 'package:bloctest/model/hotkey_model.dart';
import 'package:bloctest/model/login_model.dart';
import 'package:bloctest/utils/Constants.dart';
import 'package:bloctest/utils/RouteUtils.dart';
import 'package:bloctest/utils/base/BasePresenter.dart';
import 'package:bloctest/utils/http/dio_instance.dart';
import 'package:bloctest/utils/sp_utils.dart';

import 'package:dio/dio.dart';

import 'login_page.dart';

class LoginPagePresenter extends BasePresenter<LoginPageState> {
  LoginPagePresenter(super.state);

  Future getUrl() async {}

  @override
  Future<void> loadData(Map<String, dynamic> loadDataParams) async {
    state?.notify();

    // TODO: implement loadData
    return super.loadData(loadDataParams);
  }

  Future<bool> loginAction(String name, String pass) async {
    var params = {
      "username": name,
      "password": pass,
    };

    Response response =
        await DioInstance.instance().doPost("user/login", params: params);
    LoginModel loginModel  =LoginModel.fromJson(response.data);
    SpUtils.setString(Constants().USERINFO, jsonEncode(loginModel));
    print(loginModel);
    return true;
  }
}
